package com.qingyouchuxing.mall.biz.controller;

import java.util.List;

import com.qingyouchuxing.mall.biz.domain.bo.MallGoodsClassifyBO;
import com.qingyouchuxing.mall.biz.domain.dto.MallGoodsClassifyFromDTO;
import com.qingyouchuxing.mall.biz.domain.vo.MallGoodsClassifyVO;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.web.annotation.RepeatSubmit;
import com.ruoyi.common.web.core.BaseController;
import jakarta.annotation.Resource;
import com.qingyouchuxing.mall.biz.service.IMallGoodsClassifyService;

import com.ruoyi.common.orm.core.page.TableDataInfo;

/**
 * 商品产品分类Controller
 *
 * @author 数据小王子
 * 2024-09-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/goodsClassify")
public class MallGoodsClassifyController extends BaseController
{
    @Resource
    private IMallGoodsClassifyService mallGoodsClassifyService;

    /**
     * 查询商品产品分类列表(分页)
     */
    @SaCheckPermission("mall:goods:classify:list")
    @GetMapping("/page")
    public TableDataInfo<MallGoodsClassifyVO> list(MallGoodsClassifyBO mallGoodsClassifyBO)
    {
        return mallGoodsClassifyService.selectPage(mallGoodsClassifyBO);
    }

    /**
     * 查询商品产品分类列表
     */
    @GetMapping("/list")
    public R<List<MallGoodsClassifyVO>> AllGoodsClassify(MallGoodsClassifyBO mallGoodsClassifyBO)
    {
        return R.ok(mallGoodsClassifyService.selectAllGoodsClassify(mallGoodsClassifyBO));
    }

    /**
     * 导出商品产品分类列表
     */
    @SaCheckPermission("mall:goods:classify:export")
    @Log(title = "商品产品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallGoodsClassifyBO mallGoodsClassifyBO)
    {
        List<MallGoodsClassifyVO> list = mallGoodsClassifyService.selectList(mallGoodsClassifyBO);
        ExcelUtil.exportExcel(list, "商品产品分类", MallGoodsClassifyVO.class, response);
    }

    /**
     * 获取商品产品分类详细信息
     */
    @SaCheckPermission("mall:goods:classify:query")
    @GetMapping(value = "/{id}")
    public R<MallGoodsClassifyVO> getInfo(@PathVariable Long id)
    {
        return R.ok(mallGoodsClassifyService.selectById(id));
    }

    /**
     * 新增商品产品分类
     */
    @SaCheckPermission("mall:goods:classify:add")
    @Log(title = "商品产品分类", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public R<Void> add(@Validated @RequestBody MallGoodsClassifyFromDTO dto)
    {
        boolean inserted = mallGoodsClassifyService.insert(dto);
        if (!inserted) {
            return R.fail("新增商品产品分类记录失败！");
        }
        return R.ok();
    }

    /**
     * 修改商品产品分类
     */
    @SaCheckPermission("mall:goods:classify:edit")
    @Log(title = "商品产品分类", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public R<Void> edit(@Validated @RequestBody MallGoodsClassifyFromDTO dto)
    {
        Boolean updated = mallGoodsClassifyService.update(dto);
        if (!updated) {
            return R.fail("修改商品产品分类记录失败!");
        }
        return R.ok();
    }

    /**
     * 删除商品产品分类
     */
    @SaCheckPermission("mall:goods:classify:remove")
    @Log(title = "商品产品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids)
    {
        boolean deleted = mallGoodsClassifyService.deleteByIds(ids);
        if (!deleted) {
            return R.fail("删除商品产品分类记录失败!");
        }
        return R.ok();
    }
}

